GITLAB_HOME="/opt/gitlab-8.14.3-0"
PATH="$GITLAB_HOME/apps/gitlabci/gitlabci-runner:$GITLAB_HOME/apps/gitlab/gitlab-shell/bin:$GITLAB_HOME/redis/bin:$GITLAB_HOME/sqlite/bin:$GITLAB_HOME/python/bin:$GITLAB_HOME/perl/bin:$GITLAB_HOME/git/bin:$GITLAB_HOME/ruby/bin:$GITLAB_HOME/mysql/bin:$GITLAB_HOME/apache2/bin:$GITLAB_HOME/common/bin:$GITLAB_HOME/nodejs/bin:$GITLAB_HOME/go/bin:$GITLAB_HOME/postgresql/bin:$PATH"

echo "backup gitlab to local storage begin.. "
cd $GITLAB_HOME/apps/gitlab/htdocs
bundle exec bin/rake gitlab:backup:create RAILS_ENV=production

file=`find /opt/gitlab-8.14.3-0/apps/gitlab/htdocs/tmp/backups/  -name "*.tar"|xargs ls -l | tail -n 1 | awk '{print $9}'`

rsync -vzurtopg $file   --delete root@192.168.1.250:/opt/gitlab-8.14.3-0/apps/gitlab/htdocs/tmp/backups/

find /opt/gitlab-8.14.3-0/apps/gitlab/htdocs/tmp/backups/ -name "*.tar"  -mtime +2|xargs rm -rf 
